package com.helei.mq_test2;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class ConnectionUtil {
    public static Connection getConnection() throws Exception {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");//ip
        factory.setPort(5672); //端口  默认值 5672
        factory.setVirtualHost("/test");//虚拟机 默认值/
        factory.setUsername("helei");//用户名
        factory.setPassword("helei");//密码
        // 通过工程获取连接
        return factory.newConnection();
    }
    public static void main(String[] args) throws Exception {
        Connection con = ConnectionUtil.getConnection();
        System.out.println(con);
        //         amqp://admin@192.168.137.118:5672/
        con.close();
    }
}
